﻿using UnityEngine;
using Network;

public class ProcInit : Proc
{
    public ProcInit()
        : base(ProcType.PROC_INIT)
    {
        
    }

    public override void process()
    {
        NetManager.Instance.Tick(Time.deltaTime);
    }

    public override void onBegin(object[] param)
    {
        RegistNetworkEvent();
        beginLogin();
    }

    public override void onEnd()
    {
        UnregistNetworkEvent();
    }

    void RegistNetworkEvent()
    {
        NetManager.Instance.tcpConc.connectionDelegate += onConnectTcpSuccess;
    }

    void UnregistNetworkEvent()
    {
        NetManager.Instance.tcpConc.connectionDelegate -= onConnectTcpSuccess;
    }

    private void beginLogin()
    {
        NetManager.Instance.Connect(Config.ServerIp, Config.TcpPort);
        //Mainloop.Instance.ctrl.changeProc(ProcType.PROC_GAME, 1, true);
        
    }

    void onConnectTcpSuccess()
    {
        Mainloop.Instance.ctrl.changeProc(ProcType.PROC_LOGIN);
    }
}
